package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.AssesRule;
import com.ruoyi.system.service.IAssesRuleService;
import com.ruoyi.system.service.IAssesRuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 考核规则Controller
 *
 * @author ruoyi
 * @date 2024-04-22
 */
@RestController
@RequestMapping("/system/assesRule")
public class AssesRuleController extends BaseController
{
    @Autowired
    private IAssesRuleService AssesRuleService;

    /**
     * 查询考核规则列表
     */
    @PreAuthorize("@ss.hasPermi('system:rule:list')")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody AssesRule assesRule)
    {
        setStartPage(assesRule.getPageNum(),assesRule.getPageSize());
        List<AssesRule> list = AssesRuleService.selectAssesRuleList(assesRule);
        return getDataTable(list);
    }

    /**
     * 获取考核规则详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:rule:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(AssesRuleService.selectAssesRuleById(id));
    }

    /**
     * 新增考核规则
     */
    @PreAuthorize("@ss.hasPermi('system:rule:add')")
    @Log(title = "考核规则", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody AssesRule assesRule)
    {
        assesRule.setCreateBy(String.valueOf(getUserId()));
        assesRule.setCreateName(getUsername());
        return AssesRuleService.insertAssesRule(assesRule);
    }

    /**
     * 修改考核规则
     */
    @PreAuthorize("@ss.hasPermi('system:rule:edit')")
    @Log(title = "考核规则", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody AssesRule assesRule)
    {
        return AssesRuleService.updateAssesRule(assesRule);
    }

    /**
     * 删除考核规则
     */
    @PreAuthorize("@ss.hasPermi('system:rule:remove')")
    @Log(title = "考核规则", businessType = BusinessType.DELETE)
	@DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id)
    {
        return toAjax(AssesRuleService.deleteAssesRuleById(id));
    }
}
